/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:58 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class DanhmuckiemtraDAL : SqlProvider<DanhmuckiemtraEntity>
    {
        static DanhmuckiemtraDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                DanhmuckiemtraEntity entity = new DanhmuckiemtraEntity();
				entity.PK_iDanhmuckiemtraID = Int16.Parse("0"+dr["PK_iDanhmuckiemtraID"].ToString());
				entity.sTendanhmuc = dr["sTendanhmuc"].ToString();
				entity.sKyhieu = dr["sKyhieu"].ToString();
				entity.iHesodiem = Int16.Parse("0"+dr["iHesodiem"].ToString());
                return entity;
            };
        }
        public static DanhmuckiemtraEntity GetOne(Int16 PK_iDanhmuckiemtraID)
        {
            string cmdName = "spDanhmuckiemtra_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iDanhmuckiemtraID", PK_iDanhmuckiemtraID);
            DanhmuckiemtraEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<DanhmuckiemtraEntity> GetAll()
        {
            string cmdName = "spDanhmuckiemtra_Get";
            return GetList(cmdName);
        }
        
        public static int Add(DanhmuckiemtraEntity entity)
        {
            string cmdName = "spDanhmuckiemtra_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(DanhmuckiemtraEntity entity)
        {
            string cmdName = "spDanhmuckiemtra_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int16 PK_iDanhmuckiemtraID)
        {
            string cmdName = "spDanhmuckiemtra_Delete";
            SqlParameter p = new SqlParameter("@PK_iDanhmuckiemtraID", PK_iDanhmuckiemtraID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(DanhmuckiemtraEntity entity)
        {
            SqlParameter[] p = new SqlParameter[4];
			p[0] = new SqlParameter("@PK_iDanhmuckiemtraID", entity.PK_iDanhmuckiemtraID);
			p[1] = new SqlParameter("@sTendanhmuc", entity.sTendanhmuc);
			p[2] = new SqlParameter("@sKyhieu", entity.sKyhieu);
			p[3] = new SqlParameter("@iHesodiem", entity.iHesodiem);
            return p;
        }
        #endregion
       
    }
}